extends BaseBridge
class_name BounceBridge

@onready var bounce_conpment: Area2D = $BounceConpment

func _ready() -> void:
	super._ready()
	bounce_conpment.body_entered.connect(on_bounce_entered)


func on_bounce_entered(body:Node2D) -> void:
	if not body.has_method("bounce"):
		return
	# 兼容 Player 和 Brick
	var velocity = Vector2.ZERO
	if "velocity" in body:
		velocity = body.velocity
		body.add_dash()
	elif "linear_velocity" in body:
		velocity = body.linear_velocity
	else:
		velocity = Vector2.UP.rotated(rotation)
	if velocity.length() == 0:
		velocity = Vector2.UP.rotated(rotation)
	var in_dir = velocity.normalized()
	var normal = Vector2.UP.rotated(rotation)
	var reflect_dir = in_dir.bounce(normal)
	body.bounce(reflect_dir)

func with_move() -> void:
	pass
	
